﻿/*-------------------------------------------------------------------------------------
 * Project Name             : Gems
 * Created By               : Nanthini
 * Created Date             : 29 Oct 2012
 * Page Function            : 
 * -------------------------------------------------------------------------------------

*/

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.Data;


public partial class vp_DealerMastert : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Request.QueryString["Dealer_id"] != null)
            {
                ViewState["ID"] = Request.QueryString["Dealer_id"];
                DisplayRecords();


            }

            DataTable dt = new DataTable();
            dt.Columns.Add("Name");
            dt.Columns.Add("officeAdd");
            dt.Columns.Add("PermanentAdd");
            dt.Columns.Add("ContactNo");
            ViewState["Name"] = dt;








        }

    }
    #region Button Event
    protected void svebtn_Click(object sender, EventArgs e)
    {
        try
        {

            SaveRecord();
        }
        catch (Exception ex)
        {
            JSAlert.Show(ex.Message);
        }


    }

    protected void clrbtn_Click(object sender, EventArgs e)
    {
        try
        {

            clear();
        }
        catch (Exception ex)
        {
            JSAlert.Show(ex.Message);
        }

    }

    protected void btn_Add_Click(object sender, EventArgs e)
    {
        try
        {
            gridview();


        }
        catch (Exception ex)
        {
            JSAlert.Show(ex.Message);
        }
    }
    protected void btn_Clear_Click(object sender, EventArgs e)
    {
        try
        {
            clearmanager();



        }
        catch (Exception ex)
        {
            JSAlert.Show(ex.Message);
        }

    }

    #endregion

    #region User Defined Function
    public void SaveRecord()
    {
        try
        {
            String id = Request.QueryString["Dealer_id"];
            Hashtable hstbl1 = new Hashtable();
            hstbl1.Add("Dealer_id", id);
            hstbl1.Add("DealerCode", txtDcode.Text.Trim());
            hstbl1.Add("DealerName", txtDname.Text.Trim());
            hstbl1.Add("CompanyName", txtCname.Text.Trim());
            hstbl1.Add("TinNo", txtDtinnumber.Text.Trim());
            hstbl1.Add("OfficeNo", txtDofficenumber.Text.Trim());
            hstbl1.Add("MobileNo", txtDmobilenumber.Text.Trim());
            hstbl1.Add("Address", txtDaddress.Text.Trim());
            hstbl1.Add("GSTNo", txtGstno.Text.Trim());
            hstbl1.Add("GCTNo", txtGctno.Text.Trim());
            hstbl1.Add("PanNo", txtPanno.Text.Trim());
            Int64 intIdentity = DataAccessLayer.ExecuteCommand_RowsAffected("GemsDealerMaster_InsertUpdate_SP", hstbl1);

            if (intIdentity > 0)
            {

                Response.Redirect("~/Master/DealerList.aspx");
            }
            else
            {
                JSAlert.Show("USER NAME ALREADY EXISTED");
            }


        }
        catch (Exception ex)
        {
            JSAlert.Show(ex.Message);
        }
    }



    public void clear()
    {
        try
        {
            if (ViewState["ID"] == null)
            {

                txtDcode.Text = string.Empty;
                txtDname.Text = string.Empty;
                txtCname.Text = string.Empty;
                txtDtinnumber.Text = string.Empty;
                txtDofficenumber.Text = string.Empty;
                txtDmobilenumber.Text = string.Empty;
                txtDaddress.Text = string.Empty;
            }
        }
        catch (Exception ex)
        {
            JSAlert.Show(ex.Message);
        }
    }

    private void DisplayRecords()
    {

        try
        {

            Hashtable hstbl = new Hashtable();
            hstbl.Add("@Dealer_id", ViewState["ID"]);
            DataSet ds = DataAccessLayer.GetDataset("GemsDealerMaster_Select_SP", hstbl);

            if (ds.Tables[0].Rows.Count > 0)
            {

                txtDcode.Text = ds.Tables[0].Rows[0]["DealerCode"].ToString();
                txtCname.Text = ds.Tables[0].Rows[0]["CompanyName"].ToString();
                txtDname.Text = ds.Tables[0].Rows[0]["DealerName"].ToString();
                txtDtinnumber.Text = ds.Tables[0].Rows[0]["TinNo"].ToString();
                txtDmobilenumber.Text = ds.Tables[0].Rows[0]["MobileNo"].ToString();
                txtDofficenumber.Text = ds.Tables[0].Rows[0]["OfficeNo"].ToString();
                txtDaddress.Text = ds.Tables[0].Rows[0]["Address"].ToString();
                txtGstno.Text = ds.Tables[0].Rows[0]["GSTNo"].ToString();
                txtGctno.Text = ds.Tables[0].Rows[0]["GCTNo"].ToString();
                txtPanno.Text = ds.Tables[0].Rows[0]["PanNo"].ToString();

            }
        }

        catch (Exception ex)
        {
            JSAlert.Show(ex.Message);
        }



    }


    private void SaveRecords()
    {

        try
        {
        }
        catch (Exception ex)
        {
            JSAlert.Show(ex.Message);
        }

    }


    private void gridview()
    {

        try
        {
            if (ViewState["Name"] != null)
            {

                DataTable dtnew = (DataTable)ViewState["Name"];
                DataRow dr = dtnew.NewRow();
                dr["Name"] = txtManagername.Text;
                dr["officeAdd"] = txtofficeaddress.Text;
                dr["ContactNo"] = txtContactno.Text;
                dr["PermanentAdd"] = txtpermanentaddress.Text;
                dtnew.Rows.Add(dr);
                ViewState["Name"] = dtnew;
                GridView1.DataSource = dtnew;
                GridView1.DataBind();
             



            }


        }
        catch (Exception ex)
        {
            JSAlert.Show(ex.Message);
        }

    }

    private void clearmanager()
    {
        try
        {

            if (ViewState["ID"] == null)
            {

                txtManagername.Text = string.Empty;
                txtofficeaddress.Text = string.Empty;
                txtpermanentaddress.Text = string.Empty;
                txtContactno.Text = string.Empty;

            }

        }
        catch (Exception ex)
        {
            JSAlert.Show(ex.Message);
        }



    }








    #endregion



}


